import React, { Component } from 'react'
import { useNavigate } from 'react-router-dom';
import { Button, Checkbox, Form, Input } from 'antd';
import '../assets/style/login.scss'
import ums from '../apis/ums'
export default function Login() {
    const navigate = useNavigate();
    const onFinish = (values) => {
        console.log('Success:', values); 
        ums.login(values).then(res=>{
          console.log(res);
          if (res.code==1) {
          localStorage.setItem('token',res.data.token)
          localStorage.setItem('refreshToken',res.data.refreshToken)
          localStorage.setItem('user',JSON.stringify(res.data.userInfo)  )
          localStorage.setItem('permissions',JSON.stringify(res.data.permissions)  )
            navigate('/NavPage/userList')
        }
       })
      };
      const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
      };
    return (
      <div className='divs'>
      <Form
    name="basic"
    labelCol={{
      span: 8,
    }}
    wrapperCol={{
      span: 16,
    }}
    style={{
      maxWidth: 300,
    }}
    onFinish={onFinish}
    onFinishFailed={onFinishFailed}
    autoComplete="off"
  >
    <Form.Item
      label={<div style={{color:'white'}}>用户名</div>}
      name="account"
      
      rules={[
        {
          required: true,
          message: '请输入用户名',
        },
      ]}
    >
      <Input placeholder='112' />
    </Form.Item>

    <Form.Item
      label={<div style={{color:'white'}}>密码</div>}
      name="password"
      rules={[
        {
          required: true,
          message: '请输入密码',
        },
      ]}
    >
      <Input.Password />
    </Form.Item>

    <Form.Item
      wrapperCol={{
        offset: 8,
        span: 16,
      }}
    >
      <Button  type="primary" htmlType="submit">
        登录
      </Button>
    </Form.Item>
  </Form></div>
    
    )
  }

